package com.ruoyi.demo.config;

import com.ruoyi.demo.util.IOUtil;
import com.ruoyi.demo.util.MinIOUtil;
import io.minio.MinioClient;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Data
@Configuration
@ConfigurationProperties(prefix = "minio")
public class MinioConfig {
    private static final Logger log = LoggerFactory.getLogger(MinioConfig.class);
    
    private String endpoint;
    private String accessKey;
    private String secretKey;
    private String bucket;
    private boolean secure;

    /**
     * 初始化 MinIO 客户端
     */

    @Bean
    public MinioClient minioClient() {
        log.info("Initializing MinIO client with config: endpoint={}, bucketName={}", endpoint, bucket);
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }

    @Bean
    public IOUtil ioUtil(MinIOUtil minIOUtil) {
        return minIOUtil;
    }
}